//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "EnergyFuture.h"
using namespace Cephei::QL::Experimental::Commodities;
#include <gen/QL/Experimental/Commodities/Quantity.h>
#include <gen/QL/Experimental/Commodities/CommodityUnitCost.h>
#include <gen/QL/Experimental/Commodities/CommodityIndex.h>
#include <gen/QL/Experimental/Commodities/CommodityType.h>
#include <gen/QL/Experimental/Commodities/PricingError.h>
#include <gen/QL/PricingEngine.h>
#include <gen/QL/Experimental/Commodities/EnergyCommodity.h>
using namespace Cephei::QL;
#define HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Experimental::Commodities::CEnergyFuture::CEnergyFuture (boost::shared_ptr<QuantLib::EnergyFuture>& childNative, Object^ owner) : CEnergyCommodity(CEnergyFuture::typeid)
{
#ifdef HANDLE
	_phEnergyFuture = NULL;
#endif
	_ppEnergyFuture = &childNative;
    _ppEnergyCommodity = new boost::shared_ptr<QuantLib::EnergyCommodity> (boost::dynamic_pointer_cast<QuantLib::EnergyCommodity> (*_ppEnergyFuture));
}
Cephei::QL::Experimental::Commodities::CEnergyFuture::CEnergyFuture (QuantLib::EnergyFuture& childNative, Object^ owner) : CEnergyCommodity(CEnergyFuture::typeid)
{
#ifdef HANDLE
	_phEnergyFuture = NULL;
#endif
	_ppEnergyFuture = new boost::shared_ptr<QuantLib::EnergyFuture> (&childNative);
    _ppEnergyCommodity = new boost::shared_ptr<QuantLib::EnergyCommodity> (boost::dynamic_pointer_cast<QuantLib::EnergyCommodity> (*_ppEnergyFuture));
    _EnergyFutureOwner = owner;
    _EnergyCommodityOwner = owner;
}

Cephei::QL::Experimental::Commodities::CEnergyFuture::CEnergyFuture (CEnergyFuture^ copy) : CEnergyCommodity(CEnergyFuture::typeid)
{
#ifdef HANDLE
	_phEnergyFuture = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppEnergyFuture = new boost::shared_ptr<QuantLib::EnergyFuture> (copy->GetShared());
        _ppEnergyCommodity = new boost::shared_ptr<QuantLib::EnergyCommodity> (boost::dynamic_pointer_cast<QuantLib::EnergyCommodity> (*_ppEnergyFuture));
    }
}
Cephei::QL::Experimental::Commodities::CEnergyFuture::CEnergyFuture (PLATFORM::Type^ t) : CEnergyCommodity(CEnergyFuture::typeid)
{
#ifdef HANDLE
	_phEnergyFuture = NULL;
#endif
	if (!t->IsSubclassOf(CEnergyFuture::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Experimental::Commodities::CEnergyFuture::CEnergyFuture (QuantLib::Handle<QuantLib::EnergyFuture>& childNative, Object^ owner)  : CEnergyCommodity(CEnergyFuture::typeid)
{
	_phEnergyFuture = &childNative;
	_ppEnergyFuture = &static_cast<boost::shared_ptr<QuantLib::EnergyFuture>>(childNative.currentLink());
    _ppEnergyCommodity = new boost::shared_ptr<QuantLib::EnergyCommodity> (boost::dynamic_pointer_cast<QuantLib::EnergyCommodity> (*_ppEnergyFuture));
    _EnergyFutureOwner = owner;
}
Cephei::QL::Experimental::Commodities::CEnergyFuture::CEnergyFuture (QuantLib::Handle<QuantLib::EnergyFuture> childNative)  : CEnergyCommodity(CEnergyFuture::typeid)
{
	_phEnergyFuture = &childNative;
	_ppEnergyFuture = &static_cast<boost::shared_ptr<QuantLib::EnergyFuture>>(childNative.currentLink());
    _ppEnergyCommodity = new boost::shared_ptr<QuantLib::EnergyCommodity> (boost::dynamic_pointer_cast<QuantLib::EnergyCommodity> (*_ppEnergyFuture));
}
#endif
#ifdef STRUCT
Cephei::QL::Experimental::Commodities::CEnergyFuture::CEnergyFuture (QuantLib::EnergyFuture childNative)  : CEnergyCommodity(CEnergyFuture::typeid)
{
#ifdef HANDLE
	_phEnergyFuture = NULL;
#endif
	_ppEnergyFuture = new boost::shared_ptr<QuantLib::EnergyFuture> (new QuantLib::EnergyFuture (childNative));
    _ppEnergyCommodity = new boost::shared_ptr<QuantLib::EnergyCommodity> (boost::dynamic_pointer_cast<QuantLib::EnergyCommodity> (*_ppEnergyFuture));
}
#endif

Cephei::QL::Experimental::Commodities::CEnergyFuture::~CEnergyFuture ()
{
    if (_ppEnergyFuture != NULL)
    {
	    delete _ppEnergyFuture;
        _ppEnergyFuture = NULL;
    }
}
Cephei::QL::Experimental::Commodities::CEnergyFuture::!CEnergyFuture ()
{
    if (_ppEnergyFuture != NULL)
    {
	    delete _ppEnergyFuture;
    }
}
QuantLib::EnergyFuture& Cephei::QL::Experimental::Commodities::CEnergyFuture::GetReference ()
{
    if (_ppEnergyFuture == NULL) throw REFNEW NativeNullException ();
	return **_ppEnergyFuture;
}
boost::shared_ptr<QuantLib::EnergyFuture>& Cephei::QL::Experimental::Commodities::CEnergyFuture::GetShared ()
{
    if (_ppEnergyFuture == NULL) throw REFNEW NativeNullException ();
	return *_ppEnergyFuture;
}
QuantLib::EnergyFuture* Cephei::QL::Experimental::Commodities::CEnergyFuture::GetPointer ()
{
    if (_ppEnergyFuture == NULL) throw REFNEW NativeNullException ();
	return &**_ppEnergyFuture;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::EnergyFuture>& Cephei::QL::Experimental::Commodities::CEnergyFuture::GetHandle ()
{
	if (_phEnergyFuture == NULL)
	{
		_phEnergyFuture = new Handle<QuantLib::EnergyFuture> (*_ppEnergyFuture);
	}
	return *_phEnergyFuture;
}
#endif
bool Cephei::QL::Experimental::Commodities::CEnergyFuture::HasNative () 
{
	return (_ppEnergyFuture != NULL);
}

Cephei::QL::Experimental::Commodities::ICommodityIndex^ Cephei::QL::Experimental::Commodities::CEnergyFuture::Index::get ()
{
    try
    {
    	boost::shared_ptr<QuantLib::CommodityIndex> _rv = (boost::shared_ptr<QuantLib::CommodityIndex>)(*_ppEnergyFuture)->index ( );   
        Cephei::QL::Experimental::Commodities::CCommodityIndex^ _nrv = REFNEW Cephei::QL::Experimental::Commodities::CCommodityIndex (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Boolean Cephei::QL::Experimental::Commodities::CEnergyFuture::IsExpired::get ()
{
    try
    {
    	bool _rv = (bool)(*_ppEnergyFuture)->isExpired ( );   
        Boolean _nrv = (Boolean)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Experimental::Commodities::IQuantity^ Cephei::QL::Experimental::Commodities::CEnergyFuture::Quantity::get ()
{
    try
    {
    	QuantLib::Quantity _rv = (QuantLib::Quantity)(*_ppEnergyFuture)->quantity ( );   
        Cephei::QL::Experimental::Commodities::CQuantity^ _nrv = REFNEW Cephei::QL::Experimental::Commodities::CQuantity (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Experimental::Commodities::ICommodityUnitCost^ Cephei::QL::Experimental::Commodities::CEnergyFuture::TradePrice::get ()
{
    try
    {
    	QuantLib::CommodityUnitCost& _rv = (QuantLib::CommodityUnitCost&)(*_ppEnergyFuture)->tradePrice ( );   
        Cephei::QL::Experimental::Commodities::CCommodityUnitCost^ _nrv = REFNEW Cephei::QL::Experimental::Commodities::CCommodityUnitCost (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

